package oj_qmfx.oj_11;


import java.util.Scanner;

class SeqStack{
    private static final int stackSize = 10;
    private int[] data;
    private int top;

//    初始化栈
    public SeqStack() {
        top = -1;
        data = new int[stackSize];
    }

    public boolean isEmpty(){
        return top == -1;
    }

    public boolean isFull(){
        return top == stackSize - 1;
    }


    public void push(int x){
        if (isFull()){
            return;
        }
        top++;
        data[top] = x;
    }

    public int pop(){
        if (isEmpty()){
            return -1;
        }
        int p = data[top];
        top--;
        return p;
    }

    public int getTop(){
        if (isEmpty()){
            return  -1;
        }
        return data[top];
    }


}


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        SeqStack stack = new SeqStack();
        for (int i = 0; i < n;i++){
            int m = sc.nextInt();
            switch (m){
                case 1:
                    int x = sc.nextInt();
                    stack.push(x);
                    break;
                case 2:
                    stack.pop();
                    break;
                case 3:
                    System.out.println(stack.getTop());
                    break;
                default:
                    break;
            }
        }
    }

}
